package net.love5z.web.common.velocity;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.love5z.web.common.utils.ServletUtils;
import net.love5z.web.common.velocity.tools.ListTool;
import net.love5z.web.common.velocity.tools.PageNavTool;

import org.apache.velocity.context.Context;
import org.springframework.web.servlet.view.velocity.VelocityView;

public class Love5zVelocityView extends VelocityView {

    @Override
    protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request,
                                            HttpServletResponse response) throws Exception {
        Context velocityContext = super.createVelocityContext(model, request, response);

        velocityContext.put("webappBaseUrl", ServletUtils.getBaseUrl(request));
        velocityContext.put("listTool", new ListTool());
        velocityContext.put("pageNavTool", new PageNavTool());

        return velocityContext;
    }

}
